package org.chipu.shared.util.singletons;

import java.net.InetAddress;
import java.util.Collection;
import org.chipu.jnids.beans.Flow;

public class JnidsUtils {
	private JnidsUtils() {/**/}

	/** @return The number of flows that uses the specified protocol */
	public static int getNConnections(Collection<Flow> flows, byte protocol) {
		int n = 0;
		for(Flow f : flows)
			if (f.protocol == protocol)
				n++;
		return n;
	}

	/** @return The number of flows that originates on the specified host */
	public static int getNConnections(Collection<Flow> flows, InetAddress orgHost) {
		int n = 0;
		for(Flow f : flows)
			if (orgHost.equals(f.orgAddress.getAddress()))
				n++;
		return n;
	}

	/** @return The number of flows that goes to the specified port */
	public static int getNConnections(Collection<Flow> flows, int port) {
		int n = 0;
		for(Flow f : flows)
			if (port == f.destAddress.getPort())
				n++;
		return n;
	}
}